package com.asset.dispoal.defaultDepartment.service.commom;

import com.asset.dispoal.defaultDepartment.domain.db.entity.GbDefaultDepartment;
import com.asset.dispoal.defaultDepartment.domain.db.mapper.GbDefaultDepartmentMapper;
import com.asset.dispoal.defaultDepartment.dto.GbDefaultDepartmentRequest;
import com.asset.dispoal.defaultDepartment.service.converter.GbDefaultDepartmentConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.core.id.BaseIdeable;
import tech.mhuang.pacebox.springboot.protocol.Result;

/**
 * @author qr
 * @date 2022/3/21$
 */
@Component
public class GbDefaultDepartmentInsertCommand implements BaseCommand<GbDefaultDepartmentRequest, Result> {

    @Autowired
    GbDefaultDepartmentMapper gbDefaultDepartmentMapper;

    @Autowired
    private BaseIdeable<String> ideable;

    @Override
    public Result execute(GbDefaultDepartmentRequest request) {
        GbDefaultDepartment gbDefaultDepartment = GbDefaultDepartmentConverter.INSTANCE.reqToDo(request);
        gbDefaultDepartment.setId(ideable.generateId());
        gbDefaultDepartmentMapper.insert(gbDefaultDepartment);
        return Result.ok();
    }
}
